# -*- coding: utf-8 -*-
"""Main Controller"""
from tg import expose, flash, require, url, request, redirect,tmpl_context,validate, config
from pylons.i18n import ugettext as _, lazy_ugettext as l_
#from catwalk.tg2 import Catwalk
from repoze.what import predicates
from formencode import validators,Schema
from lifepyscle.lib.base import BaseController
from lifepyscle.lib.uploader import *
from lifepyscle.model import DBSession, metadata
from lifepyscle.controllers.error import ErrorController
from lifepyscle import model
from lifepyscle.model import *
from lifepyscle.controllers.secure import SecureController
from lifepyscle.widgets.eventtype import event_type_form

cat="event_type" # added to every returned dict

class EventTypeController(BaseController):

    @expose()
    def index(self, **kw):
        redirect(url('/eventtype/list'))

    @expose('lifepyscle.templates.list_eventtype')
    def list(self,**kw):
        try:
            etypes = DBSession.query(EventType).all()
        except:
            etypes = []
            flash("No event types found","info")
        else:
            flash("%d event types found"%len(etypes),"ok")
            tmpl_context.event_type_form = event_type_form
        return dict(cat=cat,etypes=etypes)

    @expose('json')
    def update(self,**kw):
        return dict(kw=kw)


